<?php
namespace Admin\Controller;
use Utuo\BackgroundController;
class PartnerNodeController extends  BackgroundController
{
	public function _initialize(){
		$this->setControllerTitle('合作商节点管理');
		$this->setActionTitle(array(
				'index' => '节点列表',
		));
		$this->setActionNav(array(
				'index',
			
		));
	}
	public function  indexAction($pid)
	{ 	$nodeIds=M('ParnterNode')->where(" partner_id=".$pid)->getField('node_id',true);
		$nodeIds=implode($nodeIds,',');
		
		$nodes=M('node')->where('status=1 and is_deleted=0')->select();
		$nodes=makeListLevel($nodes,0,'pid');
		$this->assign("nodes",$nodes);
		$this->assign("nodeIds",$nodeIds);
		$this->assign("pid",$pid);
	   $this->display();
	}
	public function setNodeAction(){
			$partner_id=I('partner_id');
			
		M('ParnterNode')->where('partner_id='.$partner_id)->delete();
		$array=I('access');
		$temparray=array();
		foreach ($array as $v)
		{
			$temp=explode('-', $v);
			$temparray[]=array(
					'partner_id'=>$partner_id,
					'node_id'=>$temp[0],
					
			);
		}
		!$temparray and $this->ajaxSuccess('配置成功');
		M('ParnterNode')->addAll($temparray)!==false?$this->ajaxSuccess('配置成功'):$this->ajaxError('配置失败');
	}
}